package com.gxa.worker.recycling.controller;

import com.gxa.core.recycling.anno.NeedToken;
import com.gxa.core.recycling.common.ExceptionCode;
import com.gxa.core.recycling.common.JsonResult;
import com.gxa.core.recycling.exception.BusinessException;
import com.gxa.core.recycling.pojo.User;
import com.gxa.core.recycling.pojo.Waste;
import com.gxa.core.recycling.pojo.WasteType;
import com.gxa.worker.recycling.service.WasteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author ：looker
 * @date ：Created in 2021/12/4 18:52
 */
@CrossOrigin
@RestController
@RequestMapping("waste")
@Api("废品控制接口")
public class WasteController {

    @Autowired
    WasteService wasteService;

    @PostMapping("/getWasteType")
    @ApiOperation("废品一级分类查询")
    @NeedToken
    public Map getWasteType() throws BusinessException {

        List<WasteType> wasteType = wasteService.getWasteType();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(wasteType);
        return jsonResult.getDataMap();
    }

    @PostMapping("/getWasteInfo")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "一级废品id", required = true, dataType = "long"),
    })
    @NeedToken
    @ApiOperation("查询指定一级废品下二级具体规格废品信息")
    public Map getWasteInfo(Long id) throws BusinessException {

        List<Waste> wasteByWasteType = wasteService.getWasteByWasteType(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(wasteByWasteType);
        return jsonResult.getDataMap();
    }

    @PostMapping("/getChangePoints")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户Id", required = true, dataType = "long"),
            @ApiImplicitParam(name = "wasteId", value = "二级废品id", required = true, dataType = "long"),
    })
    @NeedToken
    @ApiOperation("根据用户等级算出对应废品的积分")
    public Map getChangePoints(Long id,Long wasteId) throws BusinessException {
        Integer exhangePoint = wasteService.getExhangePoint(id, wasteId);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setData(exhangePoint);
        return jsonResult.getDataMap();
    }

}
